#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include<vector>
using namespace std;

int main() {
    int n = 0, q = 0;
    cin >> n >> q;
    vector<long long int> arr; arr.resize(n + 1, 0);
    vector<long long int> dp; dp.resize(n + 1, 0);
    for (int i = 1; i <= n; i++)
    {
        cin >> arr[i];
        dp[i] = dp[i - 1] + arr[i];
    }
    int left = 0, right = 0;
    while (q--)
    {
        cin >> left >> right;
        cout << dp[right] - dp[left - 1] << endl;
    }
    return 0;
}


#include <iostream>
#include<vector>
using namespace std;

int main() {
    int n, m, q;
    cin >> n >> m >> q;
    vector<long long int> arrm(m + 1);
    vector<vector<long long int>> arrn(n + 1, arrm);
    vector<vector<long long int>> dp(n + 1, arrm);
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            cin >> arrn[i][j];
            dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + arrn[i][j];
        }
    }
    int x1, y1, x2, y2;
    while (q--)
    {
        cin >> x1 >> y1 >> x2 >> y2;
        cout << dp[x2][y2] - dp[x1 - 1][y2] - dp[x2][y1 - 1] + dp[x1 - 1][y1 - 1] << endl;
    }
}